var isUpPlatformInfo = null;
var offset=0;
var limit=20;
var pagingLimit=20;//显示分页时的条数
var currentTotalElements=0;//当前显示总条数
var pageLoading=false;//是否能滚动加载
var hasShowPages=false;//是否已显示分页
var firstLoadPages=true;//分页初始化时 不自动加载
//筛选条件,
var search_carNumber=null;
var search_employName=null;
var search_companyName=null;
var search_carType=null;
var search_status=[];
var upload_car = [];
$(function(){
    //初始化
    initdata(false);
    
    
    
});

$(document).ready(function(){
	
});


function initdata(isappend){
    $.ajax({
        url : ctx+'/zhuanche/'+carId+'/insurance',
        type:'GET',
        async:false,
        dataType : 'json',
        success : function(result){
            var totalElements=result.totalElements;
            if(!isappend){
                $("#car_tbody .grid-data").remove();
            }
            $("#car_tbody .grid-data").each(function(index,element){
                $(element).fadeIn(200+(index*35));
            });
            if(!hasShowPages){
                if(!isappend){
                    currentTotalElements=result.content.length;
                    pageLoading=true;
                }else{
                    if(currentTotalElements<totalElements){
                        currentTotalElements+=result.content.length;
                        pageLoading=true;
                    }else{
                        pageLoading=false;
                    }
                }
            }

            if(hasShowPages){
                firstLoadPages=true;
                $(".pageshow li a").html("共"+totalElements+" 条数据");
                $(".pagedata").paging(totalElements, {
                    format: '[< ncnnn >]',
                    perpage: pagingLimit,
                    page:(offset/limit)+1,
                    onSelect: function (page) {
                        limit=pagingLimit;
                        offset=(page-1)*limit;
                        if(!firstLoadPages){
                            initdata(false);
                        }
                        firstLoadPages=false;
                        return false;
                    },
                    onFormat: function (type) {
                        switch (type) {
                            case 'block': // n and c
                                if (!this.active)
                                    return '';
                                else if (this.value != this.page)
                                    return '<li><a href="#">' + this.value + '</a></li>';
                                return '<li class="active"><a href="#">' + this.value + '</a></li>';
                            case 'next': // >
                                return '<li><a href="#">&rsaquo;</a><li>';
                            case 'prev': // <
                                return '<li><a href="#">&lsaquo;</a><li>';
                            case 'first': // [
                                return '<li><a href="#">&laquo;</a><li>';
                            case 'last': // ]
                                return '<li><a href="#">&raquo;</a></li>';
                        }
                    }
                });
            }else{
                pageLoading=false;
                hasShowPages=true;
                $(".pageshow").show();
                $(".pagedata").show();
                $(".pageshow li a").html("共"+totalElements+" 条数据");
                $(".pagedata").paging(totalElements, {
                    format: '[< ncnnn >]',
                    perpage: pagingLimit,
                    onSelect: function (page) {
                        limit=pagingLimit;
                        offset=(page-1)*limit;
                        if(!firstLoadPages){
                            initdata(false);
                        }
                        firstLoadPages=false;
                        return false;
                    },
                    onFormat: function (type) {
                        switch (type) {
                            case 'block': // n and c
                                if (!this.active)
                                    return '';
                                else if (this.value != this.page)
                                    return '<li><a href="#">' + this.value + '</a></li>';
                                return '<li class="active"><a href="#">' + this.value + '</a></li>';
                            case 'next': // >
                                return '<li><a href="#">&rsaquo;</a><li>';
                            case 'prev': // <
                                return '<li><a href="#">&lsaquo;</a><li>';
                            case 'first': // [
                                return '<li><a href="#">&laquo;</a><li>';
                            case 'last': // ]
                                return '<li><a href="#">&raquo;</a></li>';
                        }
                    }
                });
            }
        }
    });


}














Date.prototype.Format = function(fmt)
{
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}
Boolean.parse = function (str) {
    switch (str.toLowerCase ()) {
        case "true":
            return true;
        case "false":
            return false;
        default:
            throw new Error ("Boolean.parse: Cannot convert string to boolean.");
    }
};
Array.prototype.remove=function(val) {
    if(val == null ){
        return false;
    }
    var flag = false;
    for(var i=0,n=0;i<this.length;i++) {
        if(this[i] != val) {
            this[n++]=this[i];
        }else{
            flag = true;
        }
    }
    if(flag){
        this.length-=1;
    }
};
function CheckImgExists(imgurl) {  
    var ImgObj = new Image(); //判断图片是否存在  
    ImgObj.src = imgurl;  
    //没有图片，则返回-1  
    if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {  
        return true;  
    } else {  
        return false;
    }  
} 
